package backstage.app.controller.levea;



import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import backstage.app.entity.Levea;
import backstage.app.entity.LevelkillStudent;
import backstage.app.mapper.InforExportMapper;
import backstage.app.mapper.LeveaMapper;
import backstage.app.mapper.LevelkillStudentMapper;
import backstage.app.mapper.StudentMapper;
import backstage.app.respont.RespontDateJson;
import backstage.app.service.impl.util.LevelkillStudentUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("${spring.application.name}/LevelkillStudent/api")
@Api("LevelkillStudent-控制器")
public class LevelkillStudentController {
	
	@Autowired
	private LevelkillStudentMapper levelkillStudentMapper;
	@Autowired
	private LeveaMapper Leveamapper;
	@Autowired
	private LevelkillStudentUtil levelkillStudentUtil;
	@Autowired
	private StudentMapper studentMapper;
	@Autowired
	private InforExportMapper inforExportMapper;
	private static final Logger logger = (Logger) LoggerFactory.getLogger(LevelkillStudentController.class);
	
	@PostMapping("/listbysid")
	@ApiOperation("根据学员sid查询，学员的技能测试")
	public RespontDateJson<?>listBySid(@RequestParam(value="sid",required = true)Integer sid){
		List<LevelkillStudent>list=null;
		try {
			 list=levelkillStudentMapper.selectByPrimarySid(sid);
			 for (LevelkillStudent levelkillStudent : list) {
			 	if(null!=levelkillStudent.getKillContextId()) {
					levelkillStudent.setLevea(Leveamapper.selectByPrimaryKey(levelkillStudent.getKillContextId()));
				}	 
			}
			 return list.size()>-1?RespontDateJson.ok(list, "查询成功"):RespontDateJson.fuall(list, "空空如也");
		} catch (Exception e) {
			logger.error("查询失败，存在空指针");
			return RespontDateJson.fuall(list, "空空如也");
		}
		 
	}
	
	
	@PostMapping("/delete")
	@ApiOperation("删除请求")
	public RespontDateJson<?>delete(@RequestParam(value="leid",required = true)Integer leid){
		int result=-1;
		try {
			result=levelkillStudentMapper.deleteByPrimaryKey(leid);
			return result>0?RespontDateJson.ok(result,"删除成功！"):RespontDateJson.fuall(result,"删除失败");
		} catch (Exception e) {
			logger.error("删除失败 result: {}",result); 
			return RespontDateJson.fuall(result,"删除失败，数据库异常");
		}
		
	}
	
	
	@PostMapping("/selectByLeid")
	@ApiOperation("根据id查询单个数据")
	public RespontDateJson<?>selectByLeId(@RequestParam(value="leid",required = true)Integer leid){
		LevelkillStudent levelkillStudent = null;
		try {
			  levelkillStudent = levelkillStudentMapper.selectByPrimaryKey(leid);
			  if(levelkillStudent != null && levelkillStudent.getKillContextId() != null) {
				  //将主信息设置进去
				  levelkillStudent.setInforExport(inforExportMapper.selectByPrimaryKeyLeveaid(levelkillStudent.getKillContextId()));
				  //主要信息student的
				  levelkillStudent.setStudent(studentMapper.selectByPrimaryKey(levelkillStudent.getSid()));
				 Levea leave = Leveamapper.selectByPrimaryKey(levelkillStudent.getKillContextId());
				 if(leave!=null) {
					 levelkillStudent.setLevea(leave);
				 }
			  }
			  return RespontDateJson.ok(levelkillStudent, "leid查询技能测试成功");
		} catch (Exception e) {
			return RespontDateJson.fuall(levelkillStudent, "leid查询技能测试失败，数据库异常了");
		}
		 
	 
	}
	 
	 
	@PostMapping("/update")
	@ApiOperation("修改")
	public RespontDateJson<?> update(
			@RequestParam(value="leId",required = true)Integer leId,
			@RequestParam(value="height",required = true)Double height,
			@RequestParam(value="width",required = true)Double width,
			@RequestParam(value="abduction",required = true)Double abduction,
			@RequestParam(value="abduction",required = true)Double fingerSpan,
			@RequestParam(value="itemContextOneFirst",required = true)Double itemContextOneFirst,
			@RequestParam(value="itemContextOneSecond",required = true)Double itemContextOneSecond,
			@RequestParam(value="itemContextOneThirdly",required = true)Double itemContextOneThirdly,
			@RequestParam(value="itemContextOneFourthly",required = false)Double itemContextOneFourthly,
			
			@RequestParam(value="itemContextTowFourthly",required = true)Double itemContextTowFirst,
			@RequestParam(value="itemContextTowSecond",required = true)Double itemContextTowSecond,
			@RequestParam(value="itemContextTowThirdly",required = false)Double itemContextTowThirdly,
			@RequestParam(value="itemContextTowFourthly",required = false)Double itemContextTowFourthly,
			
			@RequestParam(value="itemContextThreeFirst",required = true)Double itemContextThreeFirst,
			@RequestParam(value="itemContextThreeSecond",required = true)Double itemContextThreeSecond,
			@RequestParam(value="itemContextThreeThirdly",required = true)Double itemContextThreeThirdly,
			@RequestParam(value="itemContextThreeFourthly",required = false)Double itemContextThreeFourthly,
			
			@RequestParam(value="itemContextFrothFirst",required = true)Double itemContextFrothFirst,
			@RequestParam(value="itemContextFrothSecond",required = true)Double itemContextFrothSecond,
			@RequestParam(value="itemContextFrothThirdly",required = true)Double itemContextFrothThirdly,
			@RequestParam(value="itemContextFrothFourthly",required = false)Double itemContextFrothFourthly,
			
			@RequestParam(value="itemContextFiveFirst",required = true)Double itemContextFiveFirst,
			@RequestParam(value="itemContextFiveSecond",required = true)Double itemContextFiveSecond,
			@RequestParam(value="itemContextFiveThirdly",required = true)Double itemContextFiveThirdly,
			@RequestParam(value="itemContextFiveFourthly",required = false)Double itemContextFiveFourthly,
			
			@RequestParam(value="itemContextSixFirst",required = true)Double itemContextSixFirst,
			@RequestParam(value="itemContextSixSecond",required = true)Double itemContextSixSecond,
			@RequestParam(value="itemContextSixThirdly",required = true)Double itemContextSixThirdly,
			@RequestParam(value="itemContextSixFourthly",required = false)Double itemContextSixFourthly,
			
			@RequestParam(value="itemContextSevenFirst",required = true)Double itemContextSevenFirst,
			@RequestParam(value="itemContextSevenSecond",required = true)Double itemContextSevenSecond,
			@RequestParam(value="itemContextSevenThirdly",required = true)Double itemContextSevenThirdly,
			@RequestParam(value="itemContextSevenFourthly",required = false)Double itemContextSevenFourthly
			){
		
		
	//	 try {
			 return  levelkillStudentUtil.update(leId, height, width, abduction, fingerSpan,
					 itemContextOneFirst, itemContextOneSecond, itemContextOneThirdly, itemContextOneFourthly,
					 itemContextTowFirst, itemContextTowSecond, itemContextTowThirdly, itemContextTowFourthly,
					 itemContextThreeFirst, itemContextThreeSecond, itemContextThreeThirdly, itemContextThreeFourthly,
					 itemContextFrothFirst, itemContextFrothSecond, itemContextFrothThirdly, itemContextFrothFourthly, 
					 itemContextFiveFirst, itemContextFiveSecond, itemContextFiveThirdly, itemContextFiveFourthly, 
					 itemContextSixFirst, itemContextSixSecond, itemContextSixThirdly, itemContextSixFourthly,
					 itemContextSevenFirst, itemContextSevenSecond, itemContextSevenThirdly, itemContextSevenFourthly);
	//	} catch (Exception e) {
	//		return RespontDateJson.ok("","修改失败");
	//	}
		 
		 
		
	}


	 
	
	@PostMapping("/insert")
	@ApiOperation("添加一个技能测试")
	public RespontDateJson<?> insert(
			@RequestParam(value="killContextId",required = true)Integer killContextId,
			@RequestParam(value="sid",required = true)Integer sid,
			@RequestParam(value="height",required = true)Double height,
			@RequestParam(value="width",required = true)Double width,
			@RequestParam(value="abduction",required = true)Double abduction,
			@RequestParam(value="abduction",required = true)Double fingerSpan,
			@RequestParam(value="itemContextOneFirst",required = true)Double itemContextOneFirst,
			@RequestParam(value="itemContextOneSecond",required = true)Double itemContextOneSecond,
			@RequestParam(value="itemContextOneThirdly",required = true)Double itemContextOneThirdly,
			@RequestParam(value="itemContextOneFourthly",required = false)Double itemContextOneFourthly,
			
			@RequestParam(value="itemContextTowFourthly",required = true)Double itemContextTowFirst,
			@RequestParam(value="itemContextTowSecond",required = true)Double itemContextTowSecond,
			@RequestParam(value="itemContextTowThirdly",required = true)Double itemContextTowThirdly,
			@RequestParam(value="itemContextTowFourthly",required = false)Double itemContextTowFourthly,
			
			@RequestParam(value="itemContextThreeFirst",required = true)Double itemContextThreeFirst,
			@RequestParam(value="itemContextThreeSecond",required = true)Double itemContextThreeSecond,
			@RequestParam(value="itemContextThreeThirdly",required = true)Double itemContextThreeThirdly,
			@RequestParam(value="itemContextThreeFourthly",required = false)Double itemContextThreeFourthly,
			
			@RequestParam(value="itemContextFrothFirst",required = true)Double itemContextFrothFirst,
			@RequestParam(value="itemContextFrothSecond",required = true)Double itemContextFrothSecond,
			@RequestParam(value="itemContextFrothThirdly",required = true)Double itemContextFrothThirdly,
			@RequestParam(value="itemContextFrothFourthly",required = false)Double itemContextFrothFourthly,
			
			@RequestParam(value="itemContextFiveFirst",required = true)Double itemContextFiveFirst,
			@RequestParam(value="itemContextFiveSecond",required = true)Double itemContextFiveSecond,
			@RequestParam(value="itemContextFiveThirdly",required = true)Double itemContextFiveThirdly,
			@RequestParam(value="itemContextFiveFourthly",required = false)Double itemContextFiveFourthly,
			
			@RequestParam(value="itemContextSixFirst",required = true)Double itemContextSixFirst,
			@RequestParam(value="itemContextSixSecond",required = true)Double itemContextSixSecond,
			@RequestParam(value="itemContextSixThirdly",required = true)Double itemContextSixThirdly,
			@RequestParam(value="itemContextSixFourthly",required = false)Double itemContextSixFourthly,
			
			@RequestParam(value="itemContextSevenFirst",required = true)Double itemContextSevenFirst,
			@RequestParam(value="itemContextSevenSecond",required = true)Double itemContextSevenSecond,
			@RequestParam(value="itemContextSevenThirdly",required = true)Double itemContextSevenThirdly,
			@RequestParam(value="itemContextSevenFourthly",required = false)Double itemContextSevenFourthly
			){ 
		 return levelkillStudentUtil.insert(killContextId, sid, height, width, abduction,
				 fingerSpan, 
				 itemContextOneFirst, itemContextOneSecond, itemContextOneThirdly, itemContextOneFourthly, 
				 itemContextTowFirst, itemContextTowSecond, itemContextTowThirdly, itemContextTowFourthly, 
				 itemContextThreeFirst, itemContextThreeSecond, itemContextThreeThirdly, itemContextThreeFourthly, 
				 itemContextFrothFirst, itemContextFrothSecond, itemContextFrothThirdly, itemContextFrothFourthly,
				 itemContextFiveFirst, itemContextFiveSecond, itemContextFiveThirdly, itemContextFiveFourthly, 
				 itemContextSixFirst, itemContextSixSecond, itemContextSixThirdly, itemContextSixFourthly, 
				 itemContextSevenFirst, itemContextSevenSecond, itemContextSevenThirdly, itemContextSevenFourthly);
	}
	
}
